package acm.蓝桥19;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;

public class A卡题了是真他妈烦 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = sc.nextInt();
		sc.nextLine();
		while (cnt-- > 0) {
			char[] t = sc.nextLine().toCharArray();
			char[] s = sc.nextLine().toCharArray();
			int ans=0;
			for (int i = 0; i < t.length; i++) {
				if (s[i] != t[i]) {
					if (i - 1 >= 0 && i + 1 < t.length && s[i - 1] != s[i] && s[i + 1] != s[i]) {
						ans++;
						s[i]=s[i]=='0'?'1':'0';
					}else {
						ans=-1;
						break;
					}
				}
			}
			System.out.println(ans);
		}
	}
	static 
	class Reader {
		static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		public Reader(Object... o) {
		}

		public int nextInt() {
			try {
				in.nextToken();
			} catch (Exception ignored) {
			}
			return (int) in.nval;
		}
	}
}
